// pages/user/index.js
var app=getApp();
 var y=app.globalData.y;
Page({
  data: {
    userinfo:{},
  },


 getUserProfile() {
   var that = this;
  wx.getUserProfile({
    desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
    success: (res) => {
      that.setData({
        userinfo:res.userInfo
      })
      wx.setStorageSync("userinfo", res.userInfo);
    }
  })
},
onShareAppMessage:function(res){
    return{
        title:'农野',
        path:'/pages/index/index',
        imageUrl:'https://6167-agriculture-4g9roniha194f9d1-1311368105.tcb.qcloud.la/Util/bg2.jpg?sign=4bec8d20b8a04877eb8b40fd9a7d3c64&t=1655946580'
    }
  },
  onShow(){
    const userinfo=wx.getStorageSync("userinfo");
    this.setData({
      userinfo,
    });


    if(y>0)
    {
        wx.showTabBarRedDot({
          index: 2,
        })
    }
    else{
        wx.hideTabBarRedDot({
          index: 2,
        })
    }
  },

  check(e){
    const {userinfo}=this.data;
    if(!userinfo ){
        wx.showToast({
          title: '请先登录',
          icon:"none"
        })
        return;
    }

    var index =  e.currentTarget.dataset.index;
    if(index == 1){
        wx.navigateTo({
            url: '/pages/collect/collect',
        });
    }else if(index == 2){
        wx.navigateTo({
            url: '/pages/pushList/pushList',
        })
    }else if(index == 3){
        wx.navigateTo({
            url: '/pages/personal/personal',
        })
    }
  },
  onPullDownRefresh:function () {
    setTimeout(()=>{ wx.stopPullDownRefresh({
    success: (res) => {}})},1000)  
  }
})